<template>
    <view class="main">
        <header-vue title="报名成功" bgColor="transparent" :back="true" :backUrl="`/views/community/activity-registration?id=${activityId}`"></header-vue>
        <view class="success-img">
            <u-image :src="IMAGE_URL + '/static/order/success_icon.png'" mode="aspectFill" width="200rpx" height="200rpx"></u-image>
            <text class="success-txt">报名成功</text>
            <text class="nxz-num" v-if="activityTitle">{{ activityTitle }}</text>
        </view>
        <view class="btn-con">
            <view class="comeback-btn btn-item" @click="goToDetail(`/views/community/activity-wall-detail?id=${this.activityId}`)">返回</view>
            <view class="look-order-btn btn-item"  @click="goToDetail('/views/mine/mypublish')">查看信息</view>
        </view>
    </view>
</template>
<script>
import headerVue from '@/components/header'
import appConfig from '@/config/app.js'
export default {
    components: {
        headerVue
    },
    data() {
        return {
            IMAGE_URL: appConfig.IMAGE_URL,
            nx_num: 0,
            activityId: '',
            activityTitle: ''
        }
    },
    computed: {
        // 从store获取活动同步数据
        activitySync() {
            return this.$store.state.activitySync
        }
    },
    onLoad(options) {
        this.activityId = options.id || ''
        // 页面加载时更新store中的is_registered状态
        this.updateRegistrationStatus()
    },
    methods: {
        goUrl(url) {
            uni.redirectTo({ url: url });
        },
        
        // 更新报名状态
        updateRegistrationStatus() {
            if (this.activitySync && this.activitySync.id === this.activityId) {
                // 更新store中的is_registered为true
                this.$store.commit('SET_ACTIVITY_SYNC', {
                    ...this.activitySync,
                    is_registered: true
                })
                
                // 获取活动标题
                this.activityTitle = this.activitySync.title || ''
            }
        },
        
        // 跳转到活动详情页
        goToDetail(url) {
            uni.redirectTo({
                url: url
            })
        }
    }
}

</script>
<style lang="scss" scoped>
.main {
    width: 100%;
    min-height: 100vh;
    background: linear-gradient( to bottom, #E6EFFF 0%, #FFFFFF 100%);

    .success-img {
        display: flex;
        justify-content: center;
        align-items: center;
        flex-direction: column;
        margin-top: 232rpx;
    }

    .success-txt {
        font-size: 36rpx;
        font-weight: bold;
        color: #333333;
        margin: 20rpx 0 0 20rpx;
    }

    .nxz-num {
        font-size: 24rpx;
        color: #0785CF;
    }

    .btn-con {
        width: 100%;
        display: flex;
        justify-content: center;
        align-items: center;
        margin-top: 76rpx;

        .btn-item {
            display: flex;
            align-items: center;
            justify-content: center;
            width: 260rpx;
            height: 80rpx;
            box-shadow: 0rpx 6rpx 12rpx 0rpx rgba(223,152,36,0.3);
            border-radius: 100rpx 100rpx 100rpx 100rpx;
            font-size: 32rpx;
            color: #FFFFFF;
            margin: 0 20rpx;

            &.comeback-btn {
                background: #DF9824;
            }

            &.look-order-btn {
                background: #0785CF;
            }
        }
    }
}
</style>